
package Orders;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class OrderMapper extends Mapper<LongWritable, Text,OrderBean, NullWritable> {
            /*0000001	Pdt_01	222.8
            0000003	Pdt_01	222.8
            0000002	Pdt_03	522.8
            0000002	Pdt_05	722.4
            0000003	Pdt_02	33.8
            0000001	Pdt_06	25.8
            0000002	Pdt_04	122.4*/
    //   LongWritable :行数据（按行读）
    //  Text :每行的内容
    // OrderBea ：把每行所需要的内容封装在OrderBean
    // NullWritable : 不存放数据
    //封装数据
    OrderBean k = new OrderBean();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        //读取一行数据
        String line = value.toString();
        //截取想要的字段
        String[] fileds = line.split("\t");
        int  order_id= Integer.parseInt(fileds[0]);//将String类型转换为int类型
        double price = Double.parseDouble(fileds[2]);//将String类型转换为double类型
        //封装数据
        k.setOrder_id(order_id);
        k.setPrice(price);

        //写出
        context.write(k,NullWritable.get());


    }
}
